<?php
require '../db_tools.php';
$user_name=$_POST['username'];
$user_pwd=$_POST['userpwd'];
$sql='SELECT * FROM bankcard WHERE CardNo='.$user_name.' AND CardPwd='.$user_pwd;
$conn=new mysqli();
$conn->connect('127.0.0.1','root','root','bank');
$db_tool=new db_tools();
$db_tool->set_coonnect($conn);
$data=$db_tool->select($sql);
//var_dump($data);
if($data[0]==null){
    echo '用户名或者账号错误<br/>';
    echo '<a href="../login.php">重新登陆</a>';
    die;
}else{
    $sql2='SELECT * FROM accountinfo WHERE AccountId=(SELECT AccountId FROM bankcard WHERE CardNo='.$user_name.' AND CardPwd='.$user_pwd.')';
    $data2=$db_tool->select($sql2);
    echo "欢迎您:".$user_name;
    echo '<br/>';
    for ($i=0;$i<count($data);$i++){
        print_r('您当前的用户信息：<br/>');
        print_r( '用户id:'.$data[$i]['AccountId'].'<br/>用户名:'.$data2[$i]['RealName'].'<br/>卡id:'.$data[$i]['CardId'].'<br/>卡号：'.$data[$i]['CardNo'].'<br/>余额：'.$data[$i]['CardMoney']);
    }
    echo '<br/><a href="changeimg.php">前往更换头像</a><br/>';
    echo '<a href="change_password.php">更改密码</a><br/>';
    setcookie('userkey',md5($user_name.$user_pwd),time()+24*3600);
    session_start();
    $_SESSION[md5($user_name.$user_pwd)]=[
        'user_name'=>$user_name,
        'user_pwd'=>$user_pwd
    ];
}

//if($user_name=='admin'&&$user_pwd='666666'){
//    echo "欢迎您:".$user_name;
//    echo '<br/><a href="changeimg.php">前往更换头像</a><br/>';
//    echo '<a href="change_password.php">更改密码</a>';
//    setcookie('userkey',md5($user_name.$user_pwd),time()+24*3600);
//    session_start();
//    $_SESSION[md5($user_name.$user_pwd)]=[
//        'user_name'=>$user_name,
//        'user_pwd'=>$user_pwd
//    ];
//}
//else{
//    header('location:../login.php');
//}